package com.ruoyi.scheme.controller;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.scheme.service.PatchService;
import com.ruoyi.scheme.vo.PatchSchemeVO;
import com.ruoyi.scheme.vo.PatchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ers/patch")
@Api(tags = "斑块信息相关接口")
public class PatchController {

    @Autowired
    private PatchService patchService;

    /**
     * 查询斑块信息
     * @param location 地理位置筛选：全部、平台、边坡
     * @param landUseType 修复类型筛选：全部、草地、林地
     * @param ecologicalProblem 生态问题筛选：全部、地质灾害、水土流失、植被退化、土壤损伤
     */
    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation("根据筛选条件查询斑块信息接口")
    @GetMapping("/search")
    public R<List<PatchVO>> search(@RequestParam(required = false) String location,
                                   @RequestParam(required = false) String landUseType,
                                   @RequestParam(required = false) String ecologicalProblem) {
        List<PatchVO> list = patchService.searchPatch(location, landUseType, ecologicalProblem);
        return R.ok(list);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @ApiOperation("查询指定斑块信息接口: 斑块信息 + 修复方案 + 工程造价")
    @GetMapping("/condition")
    public R<List<PatchSchemeVO>> get(@RequestParam(name = "location", required = false) String location,
                          @RequestParam(name = "landUseType", required = false) String landUseType,
                          @RequestParam(name = "ecologicalProblem", required = false) String ecologicalProblem) {
        List<PatchSchemeVO> patchVO = patchService.condition(location, landUseType, ecologicalProblem);
        return R.ok(patchVO);
    }


}